

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Moe Wang">
  <meta name="keywords" content="">
  
    <meta name="description" content="前言这两天在研究Cesium中如何实现沿线飞行或漫游功能，上网查资料发现有好多博主的解决办法都包含了什么什么Property……勾起了我强烈的好奇心，遂去了Cesium官网一探究竟，一下我就被第一句话震惊到了。  All values we define for our entities are stored as Property objects.  实体的所有值都被维护成了Property对象">
<meta property="og:type" content="article">
<meta property="og:title" content="Cesium的Property机制究竟有多香">
<meta property="og:url" content="https://moewang0321.github.io/2021/06/07/Cesium%E7%9A%84Property%E6%9C%BA%E5%88%B6%E7%A9%B6%E7%AB%9F%E6%9C%89%E5%A4%9A%E9%A6%99/index.html">
<meta property="og:site_name" content="moe_大杂烩">
<meta property="og:description" content="前言这两天在研究Cesium中如何实现沿线飞行或漫游功能，上网查资料发现有好多博主的解决办法都包含了什么什么Property……勾起了我强烈的好奇心，遂去了Cesium官网一探究竟，一下我就被第一句话震惊到了。  All values we define for our entities are stored as Property objects.  实体的所有值都被维护成了Property对象">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/9a6b5c8b8dff453ab719bee1f111e456~tplv-k3u1fbpfcp-watermark.image">
<meta property="og:image" content="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/dde462283c494bd1a7feee67cb351356~tplv-k3u1fbpfcp-watermark.image">
<meta property="og:image" content="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/eb8bd5dc606949e8a060baf0f1f06f63~tplv-k3u1fbpfcp-watermark.image">
<meta property="og:image" content="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/e3831511fc064adda66b8eac39162d2e~tplv-k3u1fbpfcp-watermark.image">
<meta property="og:image" content="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/7c16a6acef6647d9a2f98852d276c413~tplv-k3u1fbpfcp-watermark.image">
<meta property="og:image" content="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0ffdccbf9898430c8b462b9ef48220f1~tplv-k3u1fbpfcp-watermark.image">
<meta property="og:image" content="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/1e7314edd2e84eccb663544a1245136d~tplv-k3u1fbpfcp-watermark.image">
<meta property="article:published_time" content="2021-06-07T02:29:50.000Z">
<meta property="article:modified_time" content="2023-02-14T08:40:33.766Z">
<meta property="article:author" content="Moe Wang">
<meta property="article:tag" content="JavaScript">
<meta property="article:tag" content="Cesium">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/9a6b5c8b8dff453ab719bee1f111e456~tplv-k3u1fbpfcp-watermark.image">
  
  
  
  <title>Cesium的Property机制究竟有多香 - moe_大杂烩</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"moewang0321.github.io","root":"/","version":"1.9.4","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>moe_大杂烩</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Cesium的Property机制究竟有多香"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2021-06-07 10:29" pubdate>
          2021年6月7日 上午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          8.5k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          72 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Cesium的Property机制究竟有多香</h1>
            
            
              <div class="markdown-body">
                
                <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>这两天在研究Cesium中如何实现沿线飞行或漫游功能，上网查资料发现有好多博主的解决办法都包含了什么什么Property……勾起了我强烈的好奇心，遂去了<a target="_blank" rel="noopener" href="https://cesium.com/docs/tutorials/creating-entities/#the-property-system">Cesium官网</a>一探究竟，一下我就被第一句话震惊到了。</p>
<blockquote>
<p>All values we define for our entities are stored as <code>Property</code> objects.</p>
</blockquote>
<p>实体的所有值都被维护成了<code>Property</code>对象，这让我不得不往下看，但我越看越气，这么重要的东西，你这啥也没讲啊。算了还是我自己研究吧。</p>
<p><img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/9a6b5c8b8dff453ab719bee1f111e456~tplv-k3u1fbpfcp-watermark.image" srcset="/img/loading.gif" lazyload alt="image-20210603163511040.png"></p>
<h2 id="什么是Property机制"><a href="#什么是Property机制" class="headerlink" title="什么是Property机制"></a>什么是Property机制</h2><p>个人感觉Cesium的Property本质上与<code>Object.defineProperties</code>类似，<code>defineProperties</code>直接封装了基本类型，如果是Object，则是引用形式。通过Property的封装，将引用或复制的权力交给了设计者，同时提供一些特殊的功能以满足需求。</p>
<h2 id="为什么要用Property"><a href="#为什么要用Property" class="headerlink" title="为什么要用Property"></a>为什么要用Property</h2><p>首先用一个例子来简单展示一下Property的作用。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// 创建盒子</span><br><span class="hljs-keyword">var</span> box = viewer.<span class="hljs-property">entities</span>.<span class="hljs-title function_">add</span>(&#123;<br>    <span class="hljs-attr">name</span>: <span class="hljs-string">&quot;box&quot;</span>,<br>    <span class="hljs-attr">position</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">Cartesian3</span>.<span class="hljs-title function_">fromDegrees</span>(<span class="hljs-number">121.54035</span>, <span class="hljs-number">38.92146</span>, <span class="hljs-number">2000</span>),<br>    <span class="hljs-attr">box</span>: &#123;<br>        <span class="hljs-attr">dimensions</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Cartesian3</span>(<span class="hljs-number">1000.0</span>, <span class="hljs-number">1000.0</span>, <span class="hljs-number">1000.0</span>),<br>    &#125;,<br>&#125;);<br></code></pre></td></tr></table></figure>

<p>假如我们想实现盒子的大小随时间变化而变化，第一想到的应该就是用<code>setInterval</code>去改变盒子的<code>dimensions</code>，但这样对性能是个不小的挑战。而Cesium提供一种机制，可以让其随时间自动变化并赋值，这就是Property。以下代码是在5秒内让盒子大小变化。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">var</span> property = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">SampledProperty</span>(<span class="hljs-title class_">Cesium</span>.<span class="hljs-property">Cartesian3</span>);<br><br>property.<span class="hljs-title function_">addSample</span>(<br>    <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Cartesian3</span>(<span class="hljs-number">1000.0</span>, <span class="hljs-number">1000.0</span>, <span class="hljs-number">1000.0</span>)<br>);<br><br>property.<span class="hljs-title function_">addSample</span>(<br>    <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>        <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>        <span class="hljs-number">5</span>,<br>        <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>    ),<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Cartesian3</span>(<span class="hljs-number">2000.0</span>, <span class="hljs-number">2000.0</span>, <span class="hljs-number">2000.0</span>)<br>);<br><br>box.<span class="hljs-property">box</span>.<span class="hljs-property">dimensions</span> = property;<br></code></pre></td></tr></table></figure>

<p>我们通过<code>addSample</code>向Property实例添加关键帧并定义想要修改的属性，最后赋值给box的<code>dimensions</code>，效果如下</p>
<p><img src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/dde462283c494bd1a7feee67cb351356~tplv-k3u1fbpfcp-watermark.image" srcset="/img/loading.gif" lazyload alt="property1.gif"></p>
<p>所以说，<strong>Property可以和时间轴进行关联，并根据时间返回对应的属性值</strong>，而Entity则可以通过返回的值动态改变实体的位置、大小等。</p>
<h2 id="Property分类及使用方法"><a href="#Property分类及使用方法" class="headerlink" title="Property分类及使用方法"></a>Property分类及使用方法</h2><p>上文中我们举例使用的<code>SampledProperty</code>提供了插值功能，还有很多Property的类型，我们可以在<a target="_blank" rel="noopener" href="https://cesium.com/docs/cesiumjs-ref-doc/">API文档</a>中搜索一下Property，整整有29个之多。</p>
<p><img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/eb8bd5dc606949e8a060baf0f1f06f63~tplv-k3u1fbpfcp-watermark.image" srcset="/img/loading.gif" lazyload alt="image-20210604095802707.png"></p>
<p>简单归类一下可以分为几类：</p>
<ul>
<li>基本类型：<code>ConstantProperty</code>，<code>SampledProperty</code>，<code>TimeIntervalCollectionProperty</code>，<code>CompositeProperty</code></li>
<li>其他类型：<code>CallbackProperty</code>，<code>ReferenceProperty</code>，<code>PropertyArray</code>，<code>PropertyBag</code>，<code>VelocityOrientationProperty</code>，<code>VelocityVectorProperty</code></li>
<li>材质类型：<code>MaterialProperty</code>及带material字样的</li>
<li>位置类型：带Position字样的</li>
</ul>
<p>同时Cesium提供了一个<code>Property</code>类作为所有类型的基类，并定义了几个公共属性及接口。</p>
<p><strong>getValue(time, result) → Cartesian3</strong></p>
<p>获取特定时间点下的属性值</p>
<table>
<thead>
<tr>
<th align="left">Name</th>
<th align="left">Type</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>time</code></td>
<td align="left"><a target="_blank" rel="noopener" href="https://cesium.com/docs/cesiumjs-ref-doc/JulianDate.html">JulianDate</a></td>
<td align="left">检索值的时间</td>
</tr>
<tr>
<td align="left"><code>result</code></td>
<td align="left"><a target="_blank" rel="noopener" href="https://cesium.com/docs/cesiumjs-ref-doc/Cartesian3.html">Cartesian3</a></td>
<td align="left">将值存储到的对象。若缺省则创建并返回新实例</td>
</tr>
</tbody></table>
<p><strong>equal</strong></p>
<p>用来判断属性值是否相等。</p>
<p>接下来我们就一些常用的Property做一下讲解和代码实现。</p>
<h3 id="基本类型"><a href="#基本类型" class="headerlink" title="基本类型"></a>基本类型</h3><h4 id="SampledProperty"><a href="#SampledProperty" class="headerlink" title="SampledProperty"></a>SampledProperty</h4><p>第一个例子中我们使用的就是它，通过添加不同时间点的Sample，在每两个时间点之间进行线性插值，这里不做演示，代码和效果都在第一个例子中了。</p>
<h4 id="TimeIntervalCollectionProperty"><a href="#TimeIntervalCollectionProperty" class="headerlink" title="TimeIntervalCollectionProperty"></a>TimeIntervalCollectionProperty</h4><p>用来指定具体时间段内的属性值，每个时间段内属性值不变。所以和<code>SampledProperty</code>不同，它呈现出的变化为跳跃式。</p>
<p><img src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/e3831511fc064adda66b8eac39162d2e~tplv-k3u1fbpfcp-watermark.image" srcset="/img/loading.gif" lazyload alt="property2.gif"></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">var</span> property = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">TimeIntervalCollectionProperty</span>(<br>    <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">Cartesian3</span><br>);<br><br><br>property.<span class="hljs-property">intervals</span>.<span class="hljs-title function_">addInterval</span>(<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">TimeInterval</span>(&#123;<br>        <span class="hljs-attr">start</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">2</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">stop</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">20</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">isStartIncluded</span>:<span class="hljs-literal">true</span>,<br>        <span class="hljs-attr">isStopIncluded</span>:<span class="hljs-literal">false</span>,<br>        <span class="hljs-attr">data</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Cartesian3</span>(<span class="hljs-number">1000.0</span>, <span class="hljs-number">1000.0</span>, <span class="hljs-number">1000.0</span>),<br>    &#125;)<br>);<br>property.<span class="hljs-property">intervals</span>.<span class="hljs-title function_">addInterval</span>(<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">TimeInterval</span>(&#123;<br>        <span class="hljs-attr">start</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">6</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">stop</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">20</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">isStartIncluded</span>:<span class="hljs-literal">true</span>,<br>        <span class="hljs-attr">isStopIncluded</span>:<span class="hljs-literal">false</span>,<br>        <span class="hljs-attr">data</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Cartesian3</span>(<span class="hljs-number">2000.0</span>, <span class="hljs-number">2000.0</span>, <span class="hljs-number">2000.0</span>),<br>    &#125;)<br>);<br>property.<span class="hljs-property">intervals</span>.<span class="hljs-title function_">addInterval</span>(<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">TimeInterval</span>(&#123;<br>        <span class="hljs-attr">start</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">10</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">stop</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">20</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">isStartIncluded</span>:<span class="hljs-literal">true</span>,<br>        <span class="hljs-attr">isStopIncluded</span>:<span class="hljs-literal">true</span>,<br>        <span class="hljs-attr">data</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Cartesian3</span>(<span class="hljs-number">3000.0</span>, <span class="hljs-number">3000.0</span>, <span class="hljs-number">3000.0</span>),<br>    &#125;)<br>);<br><br>box.<span class="hljs-property">box</span>.<span class="hljs-property">dimensions</span> = property;<br></code></pre></td></tr></table></figure>

<h4 id="ConstantProperty"><a href="#ConstantProperty" class="headerlink" title="ConstantProperty"></a>ConstantProperty</h4><p>不随时间的变化而变化的属性。</p>
<p>相对于上述两种Property，更加常用的可能就是这个<code>ConstantProperty</code>了，在我们平常设置实体的属性时一般都是如下设置：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs js">box.<span class="hljs-property">box</span>.<span class="hljs-property">dimensions</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Cartesian3</span>(<span class="hljs-number">100</span>, <span class="hljs-number">100</span>, <span class="hljs-number">100</span>);<br></code></pre></td></tr></table></figure>

<p>但是实际上其实完整的写法应该是：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs js">box.<span class="hljs-property">box</span>.<span class="hljs-property">dimensions</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ConstantProperty</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Cartesian3</span>(<span class="hljs-number">100</span>, <span class="hljs-number">100</span>, <span class="hljs-number">100</span>));<br></code></pre></td></tr></table></figure>

<p>这么看我们可以发现，box中的<code>dismensions</code>属性其实是<code>Property</code>类型，在Cesium内部偷偷的将我们传入的Cartesian3转化成了<code>ConstantProperty</code>类型。</p>
<p><code>ConstantProperty</code>也并非不能更改，它提供了<code>setValue</code>方法去修改属性值，利用<code>setValue</code>会修改原有的属性值，而非创建新的<code>ConstantProperty</code>。</p>
<h4 id="CompositeProperty"><a href="#CompositeProperty" class="headerlink" title="CompositeProperty"></a>CompositeProperty</h4><p><img src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/7c16a6acef6647d9a2f98852d276c413~tplv-k3u1fbpfcp-watermark.image" srcset="/img/loading.gif" lazyload alt="property3.gif"></p>
<p>顾名思义这是个复合属性，它可以将多种Property进行组合操作，例如在一段时间内需要跳跃性变化，然后进行平滑变化，则可以使用这种类型。看代码：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">var</span> lineProperty = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">SampledProperty</span>(<span class="hljs-title class_">Cesium</span>.<span class="hljs-property">Cartesian3</span>);<br><br>lineProperty.<span class="hljs-title function_">addSample</span>(<br>    <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Cartesian3</span>(<span class="hljs-number">1000.0</span>, <span class="hljs-number">1000.0</span>, <span class="hljs-number">1000.0</span>)<br>);<br><br>lineProperty.<span class="hljs-title function_">addSample</span>(<br>    <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>        <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>        <span class="hljs-number">5</span>,<br>        <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>    ),<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Cartesian3</span>(<span class="hljs-number">3000.0</span>, <span class="hljs-number">3000.0</span>, <span class="hljs-number">3000.0</span>)<br>);<br><br><span class="hljs-keyword">var</span> timeProperty = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">TimeIntervalCollectionProperty</span>(<br>    <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">Cartesian3</span><br>);<br><br>timeProperty.<span class="hljs-property">intervals</span>.<span class="hljs-title function_">addInterval</span>(<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">TimeInterval</span>(&#123;<br>        <span class="hljs-attr">start</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">5</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">stop</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">20</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">isStartIncluded</span>: <span class="hljs-literal">true</span>,<br>        <span class="hljs-attr">isStopIncluded</span>: <span class="hljs-literal">false</span>,<br>        <span class="hljs-attr">data</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Cartesian3</span>(<span class="hljs-number">3000.0</span>, <span class="hljs-number">3000.0</span>, <span class="hljs-number">3000.0</span>),<br>    &#125;)<br>);<br>timeProperty.<span class="hljs-property">intervals</span>.<span class="hljs-title function_">addInterval</span>(<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">TimeInterval</span>(&#123;<br>        <span class="hljs-attr">start</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">10</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">stop</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">20</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">isStartIncluded</span>: <span class="hljs-literal">true</span>,<br>        <span class="hljs-attr">isStopIncluded</span>: <span class="hljs-literal">false</span>,<br>        <span class="hljs-attr">data</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Cartesian3</span>(<span class="hljs-number">4000.0</span>, <span class="hljs-number">4000.0</span>, <span class="hljs-number">4000.0</span>),<br>    &#125;)<br>);<br>timeProperty.<span class="hljs-property">intervals</span>.<span class="hljs-title function_">addInterval</span>(<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">TimeInterval</span>(&#123;<br>        <span class="hljs-attr">start</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">15</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">stop</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">20</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">isStartIncluded</span>: <span class="hljs-literal">true</span>,<br>        <span class="hljs-attr">isStopIncluded</span>: <span class="hljs-literal">true</span>,<br>        <span class="hljs-attr">data</span>: <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Cartesian3</span>(<span class="hljs-number">5000.0</span>, <span class="hljs-number">5000.0</span>, <span class="hljs-number">5000.0</span>),<br>    &#125;)<br>);<br><br><span class="hljs-keyword">var</span> compositeProperty = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">CompositeProperty</span>();<br>compositeProperty.<span class="hljs-property">intervals</span>.<span class="hljs-title function_">addInterval</span>(<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">TimeInterval</span>(&#123;<br>        <span class="hljs-attr">start</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>        <span class="hljs-attr">stop</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">5</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">isStartIncluded</span>: <span class="hljs-literal">false</span>,<br>        <span class="hljs-attr">isStopIncluded</span>: <span class="hljs-literal">false</span>,<br>        <span class="hljs-attr">data</span>: lineProperty,<br>    &#125;)<br>);<br>compositeProperty.<span class="hljs-property">intervals</span>.<span class="hljs-title function_">addInterval</span>(<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">TimeInterval</span>(&#123;<br>        <span class="hljs-attr">start</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">5</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">stop</span>: <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>            <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>            <span class="hljs-number">20</span>,<br>            <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>        ),<br>        <span class="hljs-attr">isStartIncluded</span>: <span class="hljs-literal">false</span>,<br>        <span class="hljs-attr">isStopIncluded</span>: <span class="hljs-literal">false</span>,<br>        <span class="hljs-attr">data</span>: timeProperty,<br>    &#125;)<br>);<br><br>box.<span class="hljs-property">box</span>.<span class="hljs-property">dimensions</span> = compositeProperty;<br></code></pre></td></tr></table></figure>

<h3 id="位置类型"><a href="#位置类型" class="headerlink" title="位置类型"></a>位置类型</h3><h4 id="PositionProperty"><a href="#PositionProperty" class="headerlink" title="PositionProperty"></a>PositionProperty</h4><p>同Property，PositionProperty是一个虚基类，不能直接实例化，它增加了<code>referenceFrame</code>，只能表示<code>position</code>。</p>
<p><code>referenceFrame</code>用来获取position的参考系，目前Cesium提供两种参考系<code>FIXED</code>和<code>INERTIAL</code>。默认使用的<code>FIXED</code>参考系，即坐标在地球上的位置是固定的。</p>
<p>基于PositionProperty的类型有以下几种：</p>
<ul>
<li>CompositePositionProperty</li>
<li>ConstantPositionProperty</li>
<li>PositionProperty</li>
<li>PositionPropertyArray</li>
<li>SampledPositionProperty</li>
<li>TimeIntervalCollectionPositionProperty</li>
</ul>
<p>用法上和基本类型基本相同，只不过它们专门用来表示位置信息。这里不做举例。</p>
<h3 id="材质类型"><a href="#材质类型" class="headerlink" title="材质类型"></a>材质类型</h3><h4 id="MaterialProperty"><a href="#MaterialProperty" class="headerlink" title="MaterialProperty"></a>MaterialProperty</h4><p>专门用来表示材质，扩展了<code>getType</code>方法来获取材质类型。</p>
<p>同样它也有很多派生类，比如<code>ColorMaterialProperty</code>，<code>ImageMaterialProperty</code>等等，我们在平时的demo和项目中也都有使用。</p>
<p>我们可以利用基本类型和材质类型实现一个颜色的动态效果。</p>
<p><img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0ffdccbf9898430c8b462b9ef48220f1~tplv-k3u1fbpfcp-watermark.image" srcset="/img/loading.gif" lazyload alt="property4.gif"></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">var</span> colorProperty = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">SampledProperty</span>(<span class="hljs-title class_">Cesium</span>.<span class="hljs-property">Color</span>);<br><br>colorProperty.<span class="hljs-title function_">addSample</span>(<br>    <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Color</span>(<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">0</span>)<br>);<br><br>colorProperty.<span class="hljs-title function_">addSample</span>(<br>    <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>        <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>        <span class="hljs-number">5</span>,<br>        <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>    ),<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Color</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>)<br>);<br><br>box.<span class="hljs-property">box</span>.<span class="hljs-property">material</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">ColorMaterialProperty</span>(colorProperty);<br><br></code></pre></td></tr></table></figure>

<h3 id="其他类型"><a href="#其他类型" class="headerlink" title="其他类型"></a>其他类型</h3><h4 id="CallbackProperty"><a href="#CallbackProperty" class="headerlink" title="CallbackProperty"></a>CallbackProperty</h4><p>这里主要介绍一下<code>CallbackProperty</code>，它是自由度最高的一种类型，我们只需要提供一个回调函数来返回我们需要的值即可，在回调函数中我们可以随意进行操作。在这我们实现一个随机变化颜色并且不断增高的box。</p>
<p><img src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/1e7314edd2e84eccb663544a1245136d~tplv-k3u1fbpfcp-watermark.image" srcset="/img/loading.gif" lazyload alt="property5.gif"></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">let</span> l = <span class="hljs-number">2000.0</span>;<br>box.<span class="hljs-property">box</span>.<span class="hljs-property">dimensions</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">CallbackProperty</span>(<span class="hljs-keyword">function</span> (<span class="hljs-params">time, result</span>) &#123;<br>    result = result || <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">Cartesian3</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>);<br><br>    l += <span class="hljs-number">20.0</span>;<br>    <span class="hljs-keyword">if</span> (l &gt; <span class="hljs-number">7000.0</span>) &#123;<br>        l = <span class="hljs-number">2000.0</span>;<br>    &#125;<br><br>    result.<span class="hljs-property">x</span> = <span class="hljs-number">4000.0</span>;<br>    result.<span class="hljs-property">y</span> = <span class="hljs-number">3000.0</span>;<br>    result.<span class="hljs-property">z</span> = l;<br>    <span class="hljs-keyword">return</span> result;<br>&#125;, <span class="hljs-literal">false</span>);<br>box.<span class="hljs-property">box</span>.<span class="hljs-property">material</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">ColorMaterialProperty</span>(<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">CallbackProperty</span>(<span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) &#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">Color</span>.<span class="hljs-title function_">fromRandom</span>(&#123;<br>            <span class="hljs-attr">alpha</span>: <span class="hljs-number">1.0</span>,<br>        &#125;);<br>    &#125;, <span class="hljs-literal">false</span>)<br>);<br></code></pre></td></tr></table></figure>

<h4 id="ReferenceProperty"><a href="#ReferenceProperty" class="headerlink" title="ReferenceProperty"></a>ReferenceProperty</h4><p>该property可以直接链接到另一个对象的Property，做引用效果。</p>
<table>
<thead>
<tr>
<th align="left">参数</th>
<th align="left">类型</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>targetCollection</code></td>
<td align="left">EntityCollection</td>
<td align="left">将用于解析引用的实体集合。</td>
</tr>
<tr>
<td align="left"><code>targetId</code></td>
<td align="left">String</td>
<td align="left">被引用的实体的 id。</td>
</tr>
<tr>
<td align="left"><code>targetPropertyNames</code></td>
<td align="left">Array.<String></td>
<td align="left">将使用的目标实体上的属性名称。</td>
</tr>
</tbody></table>
<h4 id="PropertyBag"><a href="#PropertyBag" class="headerlink" title="PropertyBag"></a>PropertyBag</h4><p>它用来对一个对象进行包装，使得该对象的每一个属性都可作为一个动态的Property进行修改。比如之前修改dimensions的话，dimensions是作为一个Cartesian3类型变量整体封装到Property中去的，如果我们只想修改dimensions的x。则可以使用PropertyBag来实现。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">var</span> zp = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">SampledProperty</span>(<span class="hljs-title class_">Number</span>);<br>zp.<span class="hljs-title function_">addSample</span>(<span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()), <span class="hljs-number">2000.0</span>);<br>zp.<span class="hljs-title function_">addSample</span>(<span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">addSeconds</span>(<br>    <span class="hljs-title class_">Cesium</span>.<span class="hljs-property">JulianDate</span>.<span class="hljs-title function_">fromDate</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()),<br>    <span class="hljs-number">5</span>,<br>    <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">JulianDate</span>()<br>),, <span class="hljs-number">7000.0</span>);<br><br>box.<span class="hljs-property">box</span>.<span class="hljs-property">dimensions</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cesium</span>.<span class="hljs-title class_">PropertyBag</span>(&#123;<br>    <span class="hljs-attr">x</span>: <span class="hljs-number">4000.0</span>,<br>    <span class="hljs-attr">y</span>: <span class="hljs-number">3000.0</span>,<br>    <span class="hljs-attr">z</span>: zp<br>&#125;);<br></code></pre></td></tr></table></figure>

<h4 id="VelocityOrientationProperty"><a href="#VelocityOrientationProperty" class="headerlink" title="VelocityOrientationProperty"></a>VelocityOrientationProperty</h4><p>该Property用来Entity的position的位置变化，来计算出移动的方向，最后把速度方向输出成Orientation。Cesium自带的示例中有一个<a target="_blank" rel="noopener" href="https://sandcastle.cesium.com/?src=Interpolation.html">Interpolation</a>中有其用法，不再赘述。</p>
<h2 id="使用场景"><a href="#使用场景" class="headerlink" title="使用场景"></a>使用场景</h2><p>Property机制很强大，我们可以在很多场景中使用它，比如实现一些沿线飞行、路径漫游或者实体的大小属性变化等。可以说只要有修改属性的地方我们都可以用到它。</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/Cesium/" class="category-chain-item">Cesium</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/JavaScript/">#JavaScript</a>
      
        <a href="/tags/Cesium/">#Cesium</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Cesium的Property机制究竟有多香</div>
      <div>https://moewang0321.github.io/2021/06/07/Cesium的Property机制究竟有多香/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Moe Wang</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2021年6月7日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/06/09/Electron%E5%AE%9E%E7%8E%B0%E5%90%AF%E5%8A%A8Loading%E5%8A%A8%E7%94%BB%E6%95%88%E6%9E%9C/" title="Electron实现启动Loading动画效果">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Electron实现启动Loading动画效果</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2021/06/03/%E3%80%90%E4%B8%89%E7%BB%B4GIS%E5%8F%AF%E8%A7%86%E5%8C%96%E3%80%91%E5%9F%BA%E4%BA%8EVue+Cesium+Supermap%E5%AE%9E%E7%8E%B0%E6%99%BA%E6%85%A7%E5%9F%8E%E5%B8%82%EF%BC%88%E4%BA%94%EF%BC%89/" title="【三维GIS可视化】基于Vue+Cesium+Supermap实现智慧城市（五）">
                        <span class="hidden-mobile">【三维GIS可视化】基于Vue+Cesium+Supermap实现智慧城市（五）</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
    <div id="giscus" class="giscus"></div>
    <script type="text/javascript">
      Fluid.utils.loadComments('#giscus', function() {
        var options = {"repo":"moewang0321/moewang0321.github.io","repo-id":"MDEwOlJlcG9zaXRvcnkyMDEyNDI0NTY=","category":"Show and tell","category-id":"DIC_kwDOC_63WM4CUMsH","theme-light":"light_protanopia","theme-dark":"dark_dimmed","mapping":"pathname","reactions-enabled":1,"emit-metadata":1,"input-position":"top","loading":"lazy","lang":"zh-CN"};
        var attributes = {};
        for (let option in options) {
          if (!option.startsWith('theme-')) {
            var key = option.startsWith('data-') ? option : 'data-' + option;
            attributes[key] = options[option];
          }
        }
        var light = 'light_protanopia';
        var dark = 'dark_dimmed';
        window.GiscusThemeLight = light;
        window.GiscusThemeDark = dark;
        attributes['data-theme'] = document.documentElement.getAttribute('data-user-color-scheme') === 'dark' ? dark : light;
        for (let attribute in attributes) {
          var value = attributes[attribute];
          if (value === undefined || value === null || value === '') {
            delete attributes[attribute];
          }
        }
        var s = document.createElement('script');
        s.setAttribute('src', 'https://giscus.app/client.js');
        s.setAttribute('crossorigin', 'anonymous');
        for (let attribute in attributes) {
          s.setAttribute(attribute, attributes[attribute]);
        }
        var ss = document.getElementsByTagName('script');
        var e = ss.length > 0 ? ss[ss.length - 1] : document.head || document.documentElement;
        e.parentNode.insertBefore(s, e.nextSibling);
      });
    </script>
    <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
